package cn.sharp.bbs.dao;

import cn.sharp.bbs.entity.DO.Report;
import cn.sharp.bbs.entity.DO.ReportReason;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ReportDao {

    @Select("select reas_id as reasonId, reas_type as reasonType, reas_name as reasonWhy " +
            "from t_reason where reas_type = #{type}")
    List<ReportReason> getReasonList(int type);

    @Insert("insert into t_reason_report(reas_id, rep_id ,rep_why) " +
            "values(#{reasonId}, #{id}, #{reasonWhy})")
    void insertReason(Long reasonId, String reasonWhy, long id);

    @Select("select rep_id as id, s_user_id as sUserId, h_user_id as hUserId, " +
            "rep_target as target, rep_type as type, rep_time as time, " +
            "rep_ptime as ptime, rep_remarks as remarks " +
            "from t_report where rep_state = #{state}")
    List<Report> selectByState(int state);

    @Select("select t_reason_report.reas_id as reasonId, reas_name as reasonWhy " +
            "from t_reason_report, t_reason " +
            "where t_reason_report.reas_id = t_reason.reas_id and " +
            "t_reason_report.reas_id != 0 and " +
            "rep_id = #{id}")
    List<ReportReason> getCommonReportReason(Long id);

    @Select("select count(*) from t_reason_report where rep_id = #{reportId} and reas_id = #{reasonId}")
    int checkReason(Long reportId, Long reasonId);

    @Select("select reas_id as reasonId, rep_why as reasonWhy " +
            "from t_reason_report " +
            "where rep_id = #{id} and " +
            "reas_id = 0")
    ReportReason getOtherReportReason(Long id);

    @Select("select user_name from t_user where user_id = #{id}")
    String getUserName(Long id);

    @Select("select com_cont from t_comment where com_id = #{id}")
    String getComment(Long id);

    String getPostName(Long id);

    @Select("select user_avatar from t_user where user_id = #{id}")
    String getUserAvatar(Long id);

    @Update("update t_report set rep_state = #{state}, h_user_id = #{u_id} where rep_id = #{id}")
    void handleReport(Long id, int state, Long u_id);

    Long getPostVersionId(Long id);

    void banPost(Long id);

    @Update("update t_comment set com_state = 1 where com_id = #{id}")
    void banComment(Long targetID);

    @Update("update t_user set user_state = 1 where user_id = #{id}")
    void banUser(Long id);


}
